
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>控制器 · 臭大佬</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Vijay">
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    

        
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="model.html" />
    
    
    <link rel="prev" href="note.html" />
    

    
    
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href=".">
        
        <link rel="apple-touch-icon" sizes="180x180" href=".">
        
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"Galloping-Vijay","repo":"laravel-wjfcms","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://www.choudalao.com" target="_blank" class="custom-link">臭大佬首页</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    前言
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="contact.html">
            
                <a href="contact.html">
            
                    
                    联系方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="reward.html">
            
                <a href="reward.html">
            
                    
                    支持与捐赠
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3" data-path="changelog.html">
            
                <a href="changelog.html">
            
                    
                    更新记录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="development.html">
            
                <a href="development.html">
            
                    
                    搭建环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="windows.html">
            
                <a href="windows.html">
            
                    
                    windows
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="linux.html">
            
                <a href="linux.html">
            
                    
                    linux
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="install.html">
            
                <a href="install.html">
            
                    
                    安装使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="installation.html">
            
                <a href="installation.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="dispose.html">
            
                <a href="dispose.html">
            
                    
                    部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="upgrade.html">
            
                <a href="upgrade.html">
            
                    
                    升级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="thinkphpwjfcms.html">
            
                <a href="thinkphpwjfcms.html">
            
                    
                    thinkphp-wjfcms获取
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="backstage.html">
            
                <a href="backstage.html">
            
                    
                    后台功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="reception.html">
            
                <a href="reception.html">
            
                    
                    前台操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="note.html">
            
                <a href="note.html">
            
                    
                    基础功能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.6.1" data-path="controller.html">
            
                <a href="controller.html">
            
                    
                    控制器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="model.html">
            
                <a href="model.html">
            
                    
                    模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="view.html">
            
                <a href="view.html">
            
                    
                    视图
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="github.html">
            
                <a href="github.html">
            
                    
                    github分支说明
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >控制器</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x6253;&#x5F00;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x63A7;&#x5236;&#x5668;&#xFF08;&#x5982;&#xFF1A;TagController &#xFF09;&#xFF0C;&#x4F1A;&#x53D1;&#x73B0;&#xFF0C;&#x91CC;&#x9762;&#x5C31;&#x4E00;&#x4E2A;index&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x662F;&#x589E;&#x5220;&#x6539;&#x67E5;&#x529F;&#x80FD;&#x5374;&#x90FD;&#x5177;&#x5907;&#x3002;</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Admin</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Traits</span>\<span class="hljs-title">TraitResource</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">Tag</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Controller</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TagController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-keyword">use</span> <span class="hljs-title">TraitResource</span>;

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span><span class="hljs-params">()</span>
    </span>{
        <span class="hljs-keyword">self</span>::$model = Tag::class;
        <span class="hljs-keyword">self</span>::$controlName = <span class="hljs-string">&apos;tag&apos;</span>;
    }

    <span class="hljs-comment">/**
     * Description:
     * User: Vijay
     * Date: 2019/7/9
     * Time: 22:53
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Contracts\View\Factory|\Illuminate\Http\Response|\Illuminate\View\View
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span><span class="hljs-params">(Request $request)</span>
    </span>{
        <span class="hljs-keyword">if</span> ($request-&gt;isMethod(<span class="hljs-string">&apos;post&apos;</span>)) {
            $page = $request-&gt;input(<span class="hljs-string">&apos;page&apos;</span>, <span class="hljs-number">1</span>);
            $limit = $request-&gt;input(<span class="hljs-string">&apos;limit&apos;</span>, <span class="hljs-number">10</span>);
            $where = [];
            $name = $request-&gt;input(<span class="hljs-string">&apos;name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>);
            $delete = $request-&gt;input(<span class="hljs-string">&apos;delete&apos;</span>, <span class="hljs-number">0</span>);
            <span class="hljs-keyword">if</span> ($name != <span class="hljs-string">&apos;&apos;</span>) {
                $where[] = [<span class="hljs-string">&apos;name&apos;</span>, <span class="hljs-string">&apos;like&apos;</span>, <span class="hljs-string">&apos;%&apos;</span> . $name . <span class="hljs-string">&apos;%&apos;</span>];
            }
            <span class="hljs-keyword">switch</span> ($delete) {
                <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;1&apos;</span>:
                    $list = <span class="hljs-keyword">self</span>::$model::onlyTrashed()-&gt;where($where)-&gt;get();
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;2&apos;</span>:
                    $list = <span class="hljs-keyword">self</span>::$model::withTrashed()-&gt;where($where)-&gt;get();
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">default</span>:
                    $list = <span class="hljs-keyword">self</span>::$model::where($where)-&gt;get();
                    <span class="hljs-keyword">break</span>;
            }
            $res = <span class="hljs-keyword">self</span>::getPageData($list, $page, $limit);
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">self</span>::resJson(<span class="hljs-number">0</span>, <span class="hljs-string">&apos;&#x83B7;&#x53D6;&#x6210;&#x529F;&apos;</span>, $res[<span class="hljs-string">&apos;data&apos;</span>], [
                    <span class="hljs-string">&apos;count&apos;</span> =&gt; $res[<span class="hljs-string">&apos;count&apos;</span>]]
            );
        }
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">&apos;admin.&apos;</span> . <span class="hljs-keyword">self</span>::$controlName . <span class="hljs-string">&apos;.index&apos;</span>, [
            <span class="hljs-string">&apos;control_name&apos;</span> =&gt; <span class="hljs-keyword">self</span>::$controlName,
            <span class="hljs-string">&apos;delete_list&apos;</span> =&gt; <span class="hljs-keyword">self</span>::$model::$delete,
        ]);
    }
}
</code></pre>
<p>&#x627E;&#x5230;TraitResource&#x6240;&#x5728;&#x76EE;&#x5F55;App\Http\Traits\TraitResource&#xFF0C;&#x5177;&#x4F53;&#x7684;&#x64CD;&#x4F5C;&#x90FD;&#x5728;&#x8FD9;&#x91CC;&#x9762;&#x3002;</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-comment">/**
 * Description:&#x8D44;&#x6E90;&#x64CD;&#x4F5C;
 * Created by PhpStorm.
 * User: Vijay
 * Date: 2019/5/26
 * Time: 12:06
 */</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Traits</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Pagination</span>\<span class="hljs-title">LengthAwarePaginator</span>;

<span class="hljs-keyword">trait</span> TraitResource
{
    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@var</span> null|string
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> $controlName = <span class="hljs-keyword">null</span>;

    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@var</span> null|string
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> $model = <span class="hljs-keyword">null</span>;

    <span class="hljs-comment">/**
     * Description:&#x5C55;&#x793A;&#x5217;&#x8868;
     * User: Vijay
     * Date: 2019/5/27
     * Time: 22:28
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Contracts\View\Factory|\Illuminate\Http\Response|\Illuminate\View\View
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span><span class="hljs-params">(Request $request)</span>
    </span>{
        <span class="hljs-keyword">if</span> ($request-&gt;isMethod(<span class="hljs-string">&apos;post&apos;</span>)) {
            $page = $request-&gt;input(<span class="hljs-string">&apos;page&apos;</span>, <span class="hljs-number">1</span>);
            $limit = $request-&gt;input(<span class="hljs-string">&apos;limit&apos;</span>, <span class="hljs-number">10</span>);
            $where = [];
            $list = <span class="hljs-keyword">self</span>::$model::where($where)-&gt;get();
            $data = <span class="hljs-keyword">self</span>::getPageData($list, $page, $limit);
            <span class="hljs-keyword">return</span> response($data);
        }
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">&apos;admin.&apos;</span> . <span class="hljs-keyword">self</span>::$controlName . <span class="hljs-string">&apos;.index&apos;</span>,
            [
                <span class="hljs-string">&apos;control_name&apos;</span> =&gt; <span class="hljs-keyword">self</span>::$controlName,
            ]);
    }

    <span class="hljs-comment">/**
     * Description:
     * User: Vijay
     * Date: 2019/5/27
     * Time: 22:28
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">create</span><span class="hljs-params">()</span>
    </span>{
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">&apos;admin.&apos;</span> . <span class="hljs-keyword">self</span>::$controlName . <span class="hljs-string">&apos;.create&apos;</span>,
            [
                <span class="hljs-string">&apos;control_name&apos;</span> =&gt; <span class="hljs-keyword">self</span>::$controlName,
            ]);
    }

    <span class="hljs-comment">/**
     * Description:
     * User: Vijay
     * Date: 2019/5/27
     * Time: 22:28
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">store</span><span class="hljs-params">(Request $request)</span>
    </span>{
        $model = <span class="hljs-keyword">new</span> <span class="hljs-keyword">self</span>::$model;
        <span class="hljs-keyword">try</span> {
            $model::create($request-&gt;input());
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">0</span>, <span class="hljs-string">&apos;&#x64CD;&#x4F5C;&#x6210;&#x529F;&apos;</span>);
        } <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> $e) {
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">1</span>, $e-&gt;getMessage());
        }
    }

    <span class="hljs-comment">/**
     * Description:
     * User: Vijay
     * Date: 2019/5/27
     * Time: 22:28
     * <span class="hljs-doctag">@param</span> $id
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">show</span><span class="hljs-params">($id)</span>
    </span>{
        $info = <span class="hljs-keyword">self</span>::$model::find($id);
        <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">0</span>, <span class="hljs-string">&apos;&#x64CD;&#x4F5C;&#x6210;&#x529F;&apos;</span>, $info);
    }

    <span class="hljs-comment">/**
     * Description:
     * User: Vijay
     * Date: 2019/5/27
     * Time: 22:29
     * <span class="hljs-doctag">@param</span> $id
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">edit</span><span class="hljs-params">($id)</span>
    </span>{
        $info = <span class="hljs-keyword">self</span>::$model::find($id);
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">&apos;admin.&apos;</span> . <span class="hljs-keyword">self</span>::$controlName . <span class="hljs-string">&apos;.edit&apos;</span>, [
            <span class="hljs-string">&apos;info&apos;</span> =&gt; $info,
            <span class="hljs-string">&apos;control_name&apos;</span> =&gt; <span class="hljs-keyword">self</span>::$controlName,
        ]);
    }

    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     * Description:
     * User: Vijay
     * Date: 2019/5/26
     * Time: 21:20
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">update</span><span class="hljs-params">(Request $request)</span>
    </span>{
        $info = <span class="hljs-keyword">self</span>::$model::find($request-&gt;id);
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">empty</span>($info)) {
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">1</span>, <span class="hljs-string">&apos;&#x6CA1;&#x6709;&#x8BE5;&#x6761;&#x8BB0;&#x5F55;&apos;</span>);
        }
        <span class="hljs-keyword">try</span> {
            $res = $info-&gt;update($request-&gt;input());
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">0</span>, <span class="hljs-string">&apos;&#x64CD;&#x4F5C;&#x6210;&#x529F;&apos;</span>, $res);
        } <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> $e) {
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">1</span>, $e-&gt;getMessage());
        }
    }

    <span class="hljs-comment">/**
     * Description:&#x5220;&#x9664;
     * User: Vijay
     * Date: 2019/5/27
     * Time: 22:11
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">destroy</span><span class="hljs-params">(Request $request)</span>
    </span>{
        <span class="hljs-keyword">try</span> {
            $res = <span class="hljs-keyword">self</span>::$model::destroy($request-&gt;id);
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">0</span>, <span class="hljs-string">&apos;&#x64CD;&#x4F5C;&#x6210;&#x529F;&apos;</span>, $res);
        } <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> $e) {
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">1</span>, $e-&gt;getMessage());
        }
    }

    <span class="hljs-comment">/**
     * Description:&#x6062;&#x590D;&#x6570;&#x636E;
     * User: Vijay
     * Date: 2019/5/27
     * Time: 22:18
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">restore</span><span class="hljs-params">(Request $request)</span>
    </span>{
        $info = <span class="hljs-keyword">self</span>::$model::onlyTrashed()-&gt;find($request-&gt;id);
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">empty</span>($info)) {
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">1</span>, <span class="hljs-string">&apos;&#x6CA1;&#x6709;&#x8BE5;&#x6761;&#x8BB0;&#x5F55;&apos;</span>);
        }
        <span class="hljs-keyword">try</span> {
            $res = $info-&gt;restore();
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">0</span>, <span class="hljs-string">&apos;&#x64CD;&#x4F5C;&#x6210;&#x529F;&apos;</span>, $res);
        } <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> $e) {
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">1</span>, $e-&gt;getMessage());
        }
    }

    <span class="hljs-comment">/**
     * Description:&#x5F7B;&#x5E95;&#x5220;&#x9664;
     * User: Vijay
     * Date: 2019/5/27
     * Time: 22:18
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">forceDelete</span><span class="hljs-params">(Request $request)</span>
    </span>{
        $info = <span class="hljs-keyword">self</span>::$model::onlyTrashed()-&gt;find($request-&gt;id);
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">empty</span>($info)) {
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">1</span>, <span class="hljs-string">&apos;&#x6CA1;&#x6709;&#x8BE5;&#x6761;&#x8BB0;&#x5F55;&apos;</span>);
        }
        <span class="hljs-keyword">try</span> {
            $res = $info-&gt;forceDelete();
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">0</span>, <span class="hljs-string">&apos;&#x64CD;&#x4F5C;&#x6210;&#x529F;&apos;</span>, $res);
        } <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> $e) {
            <span class="hljs-keyword">return</span> $this-&gt;resJson(<span class="hljs-number">1</span>, $e-&gt;getMessage());
        }
    }

    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@param</span> object|array $list &#x83B7;&#x53D6;&#x7684;&#x6570;&#x636E;
     * <span class="hljs-doctag">@param</span> int $page &#x5F53;&#x524D;&#x9875;&#x6570;
     * <span class="hljs-doctag">@param</span> int $limit &#x6CA1;&#x6709;&#x6570;&#x91CF;
     * <span class="hljs-doctag">@return</span> array
     * Description:&#x83B7;&#x53D6;&#x5206;&#x9875;&#x6570;&#x636E;
     * User: Vijay
     * Date: 2019/5/26
     * Time: 15:45
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getPageData</span><span class="hljs-params">($list, $page, $limit)</span>: <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">if</span> (is_object($list)) {
            $listArr = $list-&gt;toArray();
        } <span class="hljs-keyword">elseif</span> (is_array($list)) {
            $listArr = $list;
        } <span class="hljs-keyword">else</span> {
            $listArr = [];
        }
        $count = count($list);
        $item = array_slice($listArr, ($page - <span class="hljs-number">1</span>) * $limit, $limit);
        $paginator = <span class="hljs-keyword">new</span> LengthAwarePaginator($item, $count, $limit, $page);
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">&apos;data&apos;</span> =&gt; $paginator-&gt;items(),
            <span class="hljs-string">&apos;count&apos;</span> =&gt; $count
        ];
    }

    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@param</span> int $code &#x8FD4;&#x56DE;&#x72B6;&#x6001;&#x7801;
     * <span class="hljs-doctag">@param</span> string $msg &#x8FD4;&#x56DE;&#x4FE1;&#x606F;
     * <span class="hljs-doctag">@param</span> null $data &#x8FD4;&#x56DE;&#x6570;&#x636E;
     * <span class="hljs-doctag">@param</span> array $additional &#x9644;&#x52A0;&#x6570;&#x636E;
     * <span class="hljs-doctag">@param</span> array $header &#x5934;&#x4FE1;&#x606F;
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     * Description:&#x8FD4;&#x56DE;json&#x6570;&#x636E;
     * User: Vijay
     * Date: 2019/5/26
     * Time: 16:41
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">resJson</span><span class="hljs-params">($code = <span class="hljs-number">0</span>, $msg = <span class="hljs-string">&apos;&apos;</span>, $data = null, array $additional = [], array $header = [])</span>
    </span>{
        $result = [
            <span class="hljs-string">&apos;code&apos;</span> =&gt; $code,
            <span class="hljs-string">&apos;msg&apos;</span> =&gt; $msg,
            <span class="hljs-string">&apos;data&apos;</span> =&gt; $data,
        ];
        <span class="hljs-keyword">if</span> (count($additional) &gt; <span class="hljs-number">0</span>) {
            <span class="hljs-keyword">foreach</span> ($additional <span class="hljs-keyword">as</span> $key =&gt; $val) {
                $result[$key] = $val;
            }
        }
        $result[<span class="hljs-string">&apos;create_time&apos;</span>] = date(<span class="hljs-string">&apos;Y-m-d H:i:s&apos;</span>, time());
        <span class="hljs-keyword">return</span> response($result)-&gt;withHeaders($header);
    }
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="note.html" class="navigation navigation-prev " aria-label="Previous page: 基础功能">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="model.html" class="navigation navigation-next " aria-label="Next page: 模型">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"控制器","level":"1.6.1","depth":2,"next":{"title":"模型","level":"1.6.2","depth":2,"path":"model.md","ref":"model.md","articles":[]},"previous":{"title":"基础功能","level":"1.6","depth":1,"path":"note.md","ref":"note.md","articles":[{"title":"控制器","level":"1.6.1","depth":2,"path":"controller.md","ref":"controller.md","articles":[]},{"title":"模型","level":"1.6.2","depth":2,"path":"model.md","ref":"model.md","articles":[]},{"title":"视图","level":"1.6.3","depth":2,"path":"view.md","ref":"view.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["-sharing","splitter","expandable-chapters-small","anchors","github","github-buttons","donate","sharing-plus","anchor-navigation-ex","favicon"],"styles":{"website":""},"pluginsConfig":{"github":{"url":"https://github.com/Galloping-Vijay/laravel-wjfcms"},"splitter":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"./images/支付宝支付.jpg","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"./images/微信支付.png","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"favicon":{"shortcut":"","bookmark":"","appleTouch":"","appleTouchMore":{"120x120":"","180x180":""}},"github-buttons":{"buttons":[{"user":"Galloping-Vijay","repo":"laravel-wjfcms","type":"star","size":"small","count":true}]},"expandable-chapters-small":{},"sharing":{"qq":false,"all":["google","facebook","weibo","twitter","qq","qzone","linkedin","pocket"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"theme":"default","author":"Vijay","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"臭大佬","language":"zh-hans","links":{"sidebar":{"臭大佬首页":"https://www.choudalao.com"}},"gitbook":"3.2.3","description":"每一次经历，每一段时光都值得被记录，它们将会是你未来的财富。"},"file":{"path":"controller.md","mtime":"2021-06-09T11:28:06.346Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-18T09:41:37.518Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

